
/**
*
* @ author: hxwy
* @ email: 928936715@qq.com
* @ date: 2020-04-14 11:19
*/
export default class SocreHint extends Laya.Script {

    prefab : Laya.Prefab;
    private static inistance : SocreHint;
    constructor() {
        super();
    }
    //单例
    static GetIniastanc() : SocreHint
    {
        return this.inistance == null?this.inistance =new SocreHint:this.inistance;
    }

    init()
    {
        Laya.loader.load("prefab/txt_Hint.json",Laya.Handler.create(this,function(prefab)
        {
            this.prefab = prefab;
        }),null,Laya.Loader.PREFAB);
    }

    onAwake()
    {
        Laya.loader.load("prefab/txt_Hint.json",Laya.Handler.create(this,function(prefab)
        {
            this.prefab = prefab;
        }),null,Laya.Loader.PREFAB);
        Laya.stage.on("CreateTxt_Hint",this,this.ShowSocre);
       
    }

    ShowSocre(socre:number)
    {
        let txt_Hint = Laya.Pool.getItemByCreateFun("txt_Hint",this.CreateFun,this)as Laya.Text;
        txt_Hint.text = "+" + socre;
        txt_Hint.pos(220,910);
        //P1对象，P2效果，P3延迟，P4运动模式
        Laya.Tween.to(txt_Hint,{y:910 - 100},500,null,Laya.Handler.create(this,function(){
            txt_Hint.removeSelf();
            Laya.Pool.recover("txt_Hint",txt_Hint);
        }));
        Laya.stage.addChild(txt_Hint);
        Laya.stage.event("AddSocre",socre);
    }
    CreateFun()
    {
        return this.prefab.create();
    }
}
